// GestureService.h

#ifndef _GESTURESERVICE_h
#define _GESTURESERVICE_h

#include <Wire.h>

#include "Listenable.h"
#include "GestureEvent.h"
#include "paj7620u2_cfg.h"

#define PAJ7620_ID           0x73    
#define PAJ_REGITER_BANK_SEL 0XEF    
#define PAJ_BANK0            0X00    
#define PAJ_BANK1            0X01    


#define PAJ_SUSPEND_CMD            0X03 
#define PAJ_SET_INT_FLAG1          0X41 
#define PAJ_SET_INT_FLAG2          0X42 
#define PAJ_GET_INT_FLAG1          0X43 
#define PAJ_GET_INT_FLAG2          0X44 
#define PAJ_GET_STATE              0X45 
#define PAJ_SET_HIGH_THRESHOLD     0x69 
#define PAJ_SET_LOW_THRESEHOLD     0X6A 
#define PAJ_GET_APPROACH_STATE     0X6B 
#define PAJ_GET_GESTURE_DATA       0X6C 
#define PAJ_GET_OBJECT_BRIGHTNESS  0XB0 
#define PAJ_GET_OBJECT_SIZE_1      0XB1 
#define PAJ_GET_OBJECT_SIZE_2      0XB2 

#define PAJ_SET_PS_GAIN         0X44 
#define PAJ_SET_IDLE_S1_STEP_0  0x67 
#define PAJ_SET_IDLE_S1_STEP_1  0x68 
#define PAJ_SET_IDLE_S2_STEP_0  0X69 
#define PAJ_SET_IDLE_S2_STEP_1  0X6A 
#define PAJ_SET_OP_TO_S1_STEP_0 0X6B 
#define PAJ_SET_OP_TO_S1_STEP_1 0X6C
#define PAJ_SET_S1_TO_S2_STEP_0 0X6D 
#define PAJ_SET_S1_TO_S2_STEP_1 0X6E
#define PAJ_OPERATION_ENABLE    0X72 

#define GES_LEFT           BIT(0) 
#define GES_RIGHT           BIT(1) 
#define GES_UP              BIT(3) 
#define GES_DOWN            BIT(2) 
#define GES_FORWARD         BIT(4) 
#define GES_BACKWARD        BIT(5) 
#define GES_CLOCKWISE       BIT(7) 
#define GES_COUNT_CLOCKWISE BIT(6) 
#define GES_WAVE            BIT(8) 


enum Bank {
    BANK0 = 0,
    BANK1,
};

class GestureService : public Listenable
{
private:
    void writeByte(uint8_t, uint8_t, uint8_t);
    uint8_t readByte(uint8_t, uint8_t);
    void readBytes(uint8_t, uint8_t, uint8_t, uint8_t *);
    void selectBank(Bank bank);
    uint8_t wakeup();
public:
    GestureService() {};
    void enterGestureMode();
    void updateGesture();
    uint8_t init();
};

extern GestureService gestureService;

#endif

